// JavaScript Document

// This script draws a google map with route examples.

/*
	Copyright 2011 Tobias Heinzer + Peter Affentranger

	This file is part of the website flugservice.ch.

    The website flugservice.ch is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The website flugservice.ch is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with the website flugservice.ch.  If not, see <http://www.gnu.org/licenses/>.
*/

      var map;
	  
	  function initialize() {
        var mapDiv = document.getElementById('map-canvas');
		
		// Define map styles
		var mapStyles = [
			{featureType: "road",
    			stylers: [
      				{ visibility: "off" }
    			]
  			},
			{featureType: "administrative.province",
    			stylers: [
      				{ visibility: "off" }
    			]
  			},
			{featureType: "landscape.natural",
    			stylers: [
      				{ visibility: "off" }
    			]
  			}];
        
		// Define map
        map = new google.maps.Map(mapDiv, {
          mapTypeId: google.maps.MapTypeId.TERRAIN,
		  styles: mapStyles
        });
		
		// Fit map with markers to available space
		var sw = new google.maps.LatLng(46.220257, 6.112347);
		var ne = new google.maps.LatLng(47.453050, 9.883361);
		var bounds = new google.maps.LatLngBounds(sw, ne);
		map.fitBounds(bounds);
		
		google.maps.event.addListenerOnce(map, 'tilesloaded', addMarkers);
      }
      
	  function addMarkers () {
		  var airfields = [
				new google.maps.LatLng(47.453050, 8.560710),
				new google.maps.LatLng(46.237090, 6.112347),
				new google.maps.LatLng(46.220257, 7.329812),
				new google.maps.LatLng(46.161285, 8.877468),	
				new google.maps.LatLng(46.532502, 9.883361)];
		  var airfieldnames = [
				"Zürich-Kloten",
				"Genf",
				"Sitten",
				"Locarno",
				"Samedan"];
		  for (i = 0; i < airfields.length; i++) {
			  var latLng = airfields[i];
			  var marker = new google.maps.Marker({
            	position: latLng,
				title: airfieldnames[i],
            	map: map
          		});
			  if (i > 0) {
				var path = [airfields[0], airfields[i]];
				var line = new google.maps.Polyline({
    				path: path,
    				strokeColor: '#ff0000',
    				strokeOpacity: 1.0,
    				strokeWeight: 2
  				});

  				line.setMap(map);
			  }
		  }
	  }

      google.maps.event.addDomListener(window, 'load', initialize);
